﻿
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "log.h"
#include "toolfun.h"
#include "haskelltool.h"
#include "barcode.h"

#include <algorithm>
#include <vector>
#include <functional>
//typedef std::function< int(share_zone_t&, share_queue_t&, share_grid_t &)> GridFunType;
#define     Min(a,b)    (a) < (b)? (a) : (b)
typedef std::function< int(int, int)> zipFunT;

static std::vector<int> zipWith1(zipFunT fun,  std::vector<int>& list1, std::vector<int> &list2)
{
    int size = std::min(list1.size(), list2.size());
    std::vector<int> resultList;
    for(int i = 0; i < size; i++)
    {
        int result = fun(list1[i], list2[i]);
        resultList.push_back(result);
    }
    return resultList;
}
static int add(int x1, int x2)
{
    return x1 + x2;
}
void logInfoP(const char *fmt, ...);
static void printVector( std::vector<int> list, const char *prestr)
{
    logInfoP("%s[ ", prestr);
    for(int i = 0; i < list.size(); i++)
    {
        logInfoP("%d ", list[i]);
    }
    logInfoP("]\n");

}

std::vector<int>
static map( std::function< int(int)>   fun,      std::vector<int> &list)
{
    std::vector<int> listNew;
    for (int i = 0; i < list.size(); i++)
    {
        int x1 = list[i];
        int x2 = fun(x1);
        listNew.push_back(x2);

    }
    return listNew;
}
int main_barcode()
{
    logInfo("***************BarCode*************");
    std::vector<int> x1 {1,2,3,4};
    std::vector<int> x2{100,1000,100,1000};
    std::vector<int> list3 = zipWith1(add,x1,x2);

    printVector(x1, "x1");
    printVector(x2, "x2");
    printVector(list3, "resultVector");


    std::vector<int> list4 = map( [](int x){return x +5;}, list3);
    printVector(list4, "resultVector");
    return 0;
}
